//
//  JSONModel.swift
//  SwiftJSON
//
//  Created by LiynXu on 2016/9/27.
//  Copyright © 2016年 LiynXu. All rights reserved.
//

import UIKit

class ApplicationsModel: NSObject {
    var applications = Array<ApplicationModel>()
    
    override func setValuesForKeysWithDictionary(keyedValues: [String : AnyObject]) {
        //根据传入的最外层的数据 取出内部的数组
        let array = keyedValues["applications"] as! [AnyObject]
        //遍历这个数据数组 新建内部对象
        for i in 0..<array.count {
            //取出每个对象所对应的字典
            let dict = array[i] as! [String:AnyObject]
            
            let app = ApplicationModel()
            
            app.setValuesForKeysWithDictionary(dict)
            
            self.applications.append(app)
            
        }
        
    }
}

class ApplicationModel: NSObject {
    var applicationId = String()
    var slug = String()
    var name = String()
    var releaseDate = String()
    var version = String()
    var descript = String()
    var categoryId = NSNumber()
    var categoryName = String()
    var iconUrl = String()
    var itunesUrl = String()
    var starCurrent = String()
    var starOverall = String()
    var ratingOverall = String()
    var downloads = String()
    var currentPrice = String()
    var lastPrice = String()
    var priceTrend = String()
    var expireDatetime = String()
    var releaseNotes = String()
    var updateDate = String()
    var fileSize = String()
    var ipa = String()
    var shares = String()
    var favorites = String()
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        if  (key as NSString) .isEqualToString("description") {
            self.descript = value as! String
        }
    }
    
    override var description: String{

        let string = "\(applicationId)\n\(itunesUrl)\n\(descript)"
        return string
    }
    
}
